<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        x: {{position.x}} <br>
        y: {{position.y}}
    </div>
    <script type="module">
        import {createApp, reactive, onMounted, onUnmounted} from './node_modules/vue/dist/vue.esm-browser.js'
        function useMousePostion () {
            // 第一个参数 props
            // 第二个参数 context attrs emit slots
            const position = reactive({
                x: 0,
                y: 0
            })
            const update = (e) => {
                position.x = e.pageX
                position.y = e.pageY
            }
            onMounted(() => {
                window.addEventListener('mousemove', update)
            })
            onUnmounted(() => {
                window.removeEventListener('mousemove', update)
            })
            return position
        }
        const app = createApp({
            setup() {
                const position = useMousePostion()
                return {
                    position
                }
            },
            mounted () {
                this.position.x = 100
            }
        })
        console.log(app)
        app.mount('#app')
    </script>
</body>
</html>
